<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:display="http://www.w3.org/1999/xhtml"
      xmlns:div.display="http://www.w3.org/1999/xhtml" xmlns:row.display="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>还款计划表修改</title>

    <!-- Bootstrap Core CSS -->
    <link th:href="@{/vendor/bootstrap/css/bootstrap.min.css}" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link th:href="@{/vendor/metisMenu/metisMenu.min.css}" rel="stylesheet">

    <!-- Custom CSS -->
    <link th:href="@{/dist/css/sb-admin-2.css}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link th:href="@{/vendor/font-awesome/css/font-awesome.min.css}" rel="stylesheet" type="text/css">

    <!--bootstrap-table CSS-->
    <link th:href="@{vendor/bootstrap/css/bootstrap-table.css}" rel="stylesheet" type="text/css">

    <link th:href="@{/vendor/datepicker/datepicker3.css}" rel="stylesheet" type="text/css">

    <!-- jQuery -->
    <script th:src="@{/vendor/jquery/jquery.min.js}"></script>

    <!-- Bootstrap Core JavaScript -->
    <script th:src="@{/vendor/bootstrap/js/bootstrap.min.js}"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script th:src="@{/vendor/metisMenu/metisMenu.min.js}"></script>

    <!-- Custom Theme JavaScript -->
    <script th:src="@{/dist/js/sb-admin-2.js}"></script>

    <script th:src="@{/vendor/datepicker/bootstrap-datepicker.js}"></script>

    <!--bootstrap-table JavaScript-->
    <script th:src="@{vendor/bootstrap/js/bootstrap-table.js}"></script>

    <script>
        $(function () {

            var Url = '/repaymentScheModify/Search?'
                + '&&refno=' + $('#refno').val();
            $('#tb_repaymentScheModify').bootstrapTable({
                url: Url,         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
//                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: queryParams,//传递参数（*）
                responseHandler: responseHandler,
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
//                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "refno",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [{
                    checkbox: true
                }, {
                    field: 'status',
                    title: '状态'
//                    formatter: function (value, row, index) {
//                        var text = '待修改';
//                        return text;
//                    }
                }, {
                    field: 'refno',
                    title: '贷款编码'
                }, {
                    field: 'cusnm',
                    title: '客户姓名'
                }, {
                    field: 'intrate',
                    title: '年利率（%）'
                }, {
                    field: 'instno',
                    title: '期数'
                }, {
                    field: 'lnamt',
                    title: '贷款金额'
                }, {
                    field: 'repaymentSchedule',
                    title: '还款计划表',
                    formatter: function (value, row, index) {
                        var userid = $('#userid').val();
                        var refno = row.refno;
                        var dwndate = row.dwndate;
                        var intrate = row.intrate;
                        var instno = row.instno;
                        var prymth = row.prymth;
                        var paymth = row.paymth;
                        var matdate = $('#matdate').val();
                        var rpyfeq = row.rpyfeq;
                        var rpyper = row.rpyper;
                        var strdate = row.strdate;
                        var fpaydat = row.fpaydat;
                        var a = '<a href="repaymentScheduleInfo?userid='+ userid +'&&refno='+ refno + '&&dwndate='+ dwndate +
                            '&&intrate='+ intrate +'&&instno='+ instno + '&&prymth='+ prymth +
                            '&&paymth='+ paymth + '&&matdate='+ matdate + '&&rpyfeq='+ rpyfeq + '&&rpyper='+ rpyper +
                            '&&strdate='+ strdate + '&&fpaydat='+ fpaydat +'" target="_blank">查看还款计划表</a>';
                        return a;
                    }
                }, {
                    field: 'loanDetails',
                    title: '贷款明细',
                    formatter: function (value, row, index) {
                        var refno = row.refno;
                        var a = '<a href="javascript:void(0)" onclick="viewLoanDetails(\' '+ refno + '\')">查看贷款明细</a>';
                        return a;
                    }
                }],

            });

        });

//        function getIntrate(refno) {
//            $.ajax({
//                type: 'POST',
//                url: '/repaymentScheModify_getIntrate',
//                contentType: 'application/json',
//                dataType: "json",
//                data: JSON.stringify({
//                    refno: refno.toString()
//                }),
//                success: function (result) {
////                    alert(result);
//                    return result;
//                },
//                error: function () {
//                    alert("获取年利率失败");
//                }
//            });
//        }

        function viewLoanDetails(refno) {
            $.ajax({
                    type: 'POST',
                    url: '/repaymentScheModify/viewLoanDetails',
                    contentType: 'application/json',
                    dataType: "json",
                    data: JSON.stringify({
                        refno: refno.toString()
                    }),
                    success: function (result) {
                        $('#refno').val(result.refno);
                        $('#status').val(result.status);
                        $('#custcod').val(result.custcod);
                        $('#cusnm').val(result.cusnm);
                        $('#dwndate').val(result.dwndate);
                        $('#intrate').val(result.intrate);
                        $('#instno').val(result.instno);
                        $('#curinno').val(result.curinno);
                        $('#prymth').val(result.prymth);
                        $('#paymth').val(result.paymth);
                        $('#matdate').val(result.matdate);
                        $('#rpyfeq').val(result.rpyfeq);
                        $('#rpyper').val(result.rpyper);
                        $('#lnccy').val(result.lnccy);
                        $('#lnamt').val(result.lnamt);
                        $('#lnosamt').val(result.lnosamt);
                        $('#strdate').val(result.strdate);
                        $('#fpaydat').val(result.fpaydat);
                        $("#loanInfo").show();
                    },
                    error: function () {
                        alert("获取贷款基本信息失败");
                    }
                });

        }

        function queryParams(params) {
            var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                limit: params.limit,   //页面大小
                offset: params.offset / params.limit + 1,  //页码
//                    refno: $("#refno").val(),
                //                    statu: $("#txt_search_statu").val()
            };
            return temp;
        }

        //请求成功方法
        function responseHandler(result) {
            var errCode = result.errCode;//在此做了错误代码的判断
            if (errCode != 0) {
                alert("错误代码" + errCode);
                return;
            }
            //如果没有错误则返回数据，渲染表格
            return {
                total: result.dataLength, //总页数,前面的key必须为"total"
                rows: result.rowDatas //行数据，前面的key要与之前设置的dataField的值一致.
            };
        };

        $(function () {
            $('#search').click(function () {
                var Url = '/repaymentScheModify/Search?'
                    + '&&refno=' + $('#queryRefno').val();
                $('#tb_repaymentScheModify').bootstrapTable("refresh", {url: Url});
            });
            
            $('#modify').click(function () {
                var userid = $('#userid').val();
                var refno = $('#refno').val();
                var dwndate = $('#dwndate').val();
                var intrate = $('#intrate').val();
                var instno = $('#instno').val();
                var prymth = $('#prymth').val();
                var paymth = $('#paymth').val();
                var matdate = $('#matdate').val();
                var rpyfeq = $('#rpyfeq').val();
                var rpyper = $('#rpyper').val();
                var strdate = $('#strdate').val();
                var fpaydat = $('#fpaydat').val();
                window.open("repaymentScheduleInfo?flag=true"+"&&"+"userid="+userid+"&&"+"refno="+refno
                    +"&&"+"dwndate="+dwndate+"&&"+"intrate="+intrate+"&&"+"instno="+instno
                    +"&&"+"prymth="+prymth+"&&"+"paymth="+paymth+"&&"+"matdate="+matdate+"&&"+"rpyfeq="+rpyfeq+"&&"+"rpyper="+rpyper
                    +"&&"+"strdate="+strdate+"&&"+"fpaydat="+fpaydat);
            })

//            $('#viewLoanDetails').click(function () {
//                alert("aaa");
//                var refno = $('#refno').val();
//                $.ajax({
//                    type: 'POST',
//                    url: '/repaymentScheModify_viewLoanDetails',
//                    contentType: 'application/json',
//                    dataType: "html",
//                    data: JSON.stringify({
//                        refno: refno.toString()
//                    }),
//                    success: function (result) {
//                        return result;
//                    },
//                    error: function () {
//                        alert("获取贷款基本信息失败");
//                    }
//                });
//                $('#loanInfo').show();
//            })
//
//            $('#viewRepaySchedule').click(function () {
//                alert("sss");
//            })

            $('#dwndate').datepicker({
                format: 'yyyymmdd',
                weekStart: 1,
                autoclose: true,
                todayBtn: 'linked',
                language: 'zh-CN'
            }).on('changeDate', function (ev) {

            });

            $('#strdate').datepicker({
                format: 'yyyymmdd',
                weekStart: 1,
                autoclose: true,
                todayBtn: 'linked',
                language: 'zh-CN'
            }).on('changeDate', function (ev) {

            });

            $('#fpaydat').datepicker({
                format: 'yyyymmdd',
                weekStart: 1,
                autoclose: true,
                todayBtn: 'linked',
                language: 'zh-CN'
            }).on('changeDate', function (ev) {

            });
        });
    </script>


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body>

<div id="repayScheModify">
    <div id="searchInfo">
        <form   name="repaymentScheModification" th:action="@{/repaymentScheModify(userid=${userid})}" th:object="${repaymentScheModify_entity1}" method="post">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">贷款编码查询信息</a>
                    </h4>
                </div>
                <div class="row" style="display:none;">
                    <input id="userid" name="userid" th:value="${userid}" class="form-control">
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <div class="row" >
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4">
                                <div class="col-lg-4">
                                    <label >贷款编码</label>
                                </div>
                                <div class="col-lg-4">
                                    <input id="queryRefno" name="queryRefno" class="form-control" >
                                </div>
                                <div class="col-lg-4">
                                    <button id="search" type="button" class="btn btn-primary">获取贷款信息</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="loanInfo" style="display:none;">
                <div class="panel panel-default">
                    <div class="panel-heading">贷款基本信息</div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>贷款编码:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{refno}" name="refno" maxlength="12" id="refno" readonly>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>当前状态:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{status}" name="status" maxlength="50" id="status" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>客户代码:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{custcod}" name="custcod" maxlength="12" id="custcod" readonly>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>客户姓名:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{cusnm}" name="cusnm" maxlength="50" id="cusnm" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>贷款放款日:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{dwndate}" name="dwndate" maxlength="12" id="dwndate">
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>年利率（%）:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{intrate}" name="intrate" maxlength="50" id="intrate">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>还款期数:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{instno}" name="instno" maxlength="12" id="instno">
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>当前期数:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{curinno}" name="curinno" maxlength="50" id="curinno" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>还款方式:</label>
                                </div>
                                <div class="col-lg-8">
                                    <select class="form-control" th:field="*{prymth}" name="prymth" maxlength="12" id="prymth">
                                        <option value="1">等额本息</option>
                                        <option value="2">等额本金</option>
                                        <option value="3">一次还本分次付息</option>
                                        <option value="4">一次性还本付息</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>还款周期:</label>
                                </div>
                                <div class="col-lg-4">
                                    <input class="form-control" th:field="*{rpyfeq}" name="rpyfeq" maxlength="50" id="rpyfeq">
                                </div>
                                <div class="col-lg-4">
                                    <input class="form-control" th:field="*{rpyper}" name="rpyper" maxlength="12" id="rpyper">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>贷款币种:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{lnccy}" name="lnccy" maxlength="12" id="lnccy" readonly>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>贷款金额:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{lnamt}" name="lnamt" maxlength="50" id="lnamt" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>贷款余额:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{lnosamt}" name="lnosamt" maxlength="12" id="lnosamt" readonly>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>下次还款日:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{strdate}" name="strdate" maxlength="50" id="strdate">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <label>首次还款日:</label>
                                </div>
                                <div class="col-lg-8">
                                    <input class="form-control" th:field="*{fpaydat}" name="fpaydat" maxlength="12" id="fpaydat">
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="col-lg-4">
                                    <button id="modify" type="button" class="btn btn-primary">修改还款计划表</button>
                                </div>
                            </div>
                        </div>
                        <div class="row" style="display:none;">
                            <input class="form-control" th:field="*{paymth}" name="paymth" maxlength="12" id="paymth">
                            <input class="form-control" th:field="*{matdate}" name="matdate" maxlength="12" id="matdate">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>



    <div id="tableDiv">
        <div class="panel panel-default">
            <div class="panel-heading">贷款信息</div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-12">
                        <table id="tb_repaymentScheModify"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>